import os
'''使用说明：
1.image_path：需检测的图片存放路径
2.same_dir:相同图片移出路径
3.设置好后直接运行即可'''
image_path = 'your input path'
same_dir = 'your output path'
if not os.path.exists(same_dir):
    os.mkdir(same_dir)

lists = os.listdir(image_path)
all_size = {}
for i in lists:
    size = os.path.getsize(os.path.join(image_path, i))
    if size in all_size:
        all_size[size].append(i)
    else: all_size[size] = [i]
print(len(all_size))
num = 0
same_images = {}
for i in all_size:
    if len(all_size[i])>1:
        images = []
        labels = []
        for j in all_size[i]:
            with open(os.path.join(image_path, j), 'rb') as f:
                image = f.read()
                if image not in same_images:
                    same_images[image] = [j]
                label = j.split('_')[2]
                if image in images and label not in labels:
                    # 图片一样标签不一样
                    same_images[image].append(j)
                    num +=1
                    #break
                elif image in images and label in labels:
                    # 图片重复标签一样
                    cmd = 'mv ' + os.path.join(image_path, j) + ' ' + same_dir
                    os.system(cmd)
                else:
                    images.append(image)
                    labels.append(label)

print(num)
num = 0
for image in same_images:
    if len(same_images[image]) > 1:
        for j in same_images[image]:
            num += 1
            cmd = 'mv ' + os.path.join(image_path, j) + ' ' + same_dir
            os.system(cmd)
print(num)